local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local CallBackManager = ClientOHOH.load.CallBackManager();
local ConnectClass=_G.CommonOHOH.load.Connect();
local UIManager = ClientOHOH.load.UIManager();
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();

function InitInsts(ui)
	ui.insts = {
        close="ctrl.close",   
        listCell="ctrl.ListCell",
        details="ctrl.Details", 
        addFriend_btn="ctrl.addFriend",
        bestEquip_btn="ctrl.bestEquip" ,
        unEquipAll_btn="ctrl.uninstallAll" ,
        equipCount="ctrl.equipCount",
        meatCount="ctrl.meatVal" 

    };
end;

function M.new(...)

	return M(...);

end;

function M.ctor(self)
	InitInsts(self)

  self.BestEquipEvent=ConnectClass.new();    --装备最佳
  self.UnEquipAllEvent=ConnectClass.new();        --卸载所有
  self.BuyEquipSlotsEvent=ConnectClass.new();     --购买槽位
  self.InvitedFriendEvent=ConnectClass.new();     --邀请好友

  self.EquipEvent=ConnectClass.new();     -- 装备好友
  self.UnEquipEvent=ConnectClass.new();     -- 卸载
  self.UpgradeEvent=ConnectClass.new();     --升级
  self.SellEvent=ConnectClass.new();          --售卖



  self.AddBroDataEvent=ConnectClass.new();     --添加好友数据

  self.ActiveBroEventEvent=ConnectClass.new();     --激活Bro信息


  self.ExitEvent=ConnectClass.new();     -- 退出
  self.EnterEvent=ConnectClass.new();     -- 进入


	M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.BroGui"));
  
  CallBackManager:AddRbxConnect(self,self.insts.close.Activated, function()
        self:Hide();
  end);


    CallBackManager:AddRbxConnect(self,self.insts.bestEquip_btn.Activated, function()
      self.BestEquipEvent:Action()
  end);

    CallBackManager:AddRbxConnect(self,self.insts.unEquipAll_btn.Activated, function()
        self.UnEquipAllEvent:Action()
    end);

    CallBackManager:AddRbxConnect(self,self.insts.addFriend_btn.Activated, function()
        self.BuyEquipSlotsEvent:Action()
    end);



  self:AddPrivateComponentByFolder(script.Com)

end;

function M.UpdateMeatCount(self,count)
  if self.meatCount then
    local dt =count-self.meatCount
    if dt==0 then
      return 
    end
    self:AddMeat(dt)
    self.insts.meatCount.Text=BigNumberHelper:ToString(count)
  else
    self.insts.meatCount.Text=BigNumberHelper:ToString(count)
  end

  self.meatCount=count
end


function M.AddMeat(self,count)
	require(self.insts.meatCount.AddCtrl.Animation).play(count)
end

function M.GetDetailsGui(self)
  return self.insts.details
end

function M.GetCellPerfab(self)
    return self.insts.listCell
end


--获取升级所波音效
function M.GetUpgradeAudio(self,...)
  return  self:WaitForChild("upgradeAudio")
end

--获取升级所播动画
function M.GetUpgradeAnimation(self,...)
  return  self:WaitForChild("upgradeAnimation")
end

--获取奔跑特效
function M.GetRunAnimation(self,...)
  return  self:WaitForChild("runAnimation")
end


function M.UpdateSlot(self,now,max,isHideBuy)
  self.insts.equipCount.Text=now.."/"..max
  if isHideBuy then
      self.insts.addFriend_btn.Visible=false
  end
end

function M.AddData(self,bro)
  self.AddBroDataEvent:Action(bro)
end

function M.OnShow(self)
  UIManager.ui_list.HomeGui:Hide()
  UIManager.ui_list.PlayerBattleInfoGui:Hide()
  self.EnterEvent:Action()
end

function M.OnHide(self)
  self.ExitEvent:Action()
  UIManager.ui_list.HomeGui:Show()
  UIManager.ui_list.PlayerBattleInfoGui:Show()

end

function M.ActiveFristBro(self)
  self:GetPrivateComponent("ListCtrl"):ActiveFristCell()
end


function M.dtor(self)
	M.super.dtor(self);
end;

return M